﻿using System;
using System.Linq;

using mvcForum.Core.Abstractions.Interfaces;
using mvcForum.Web.Attributes;
using System.IO;
using mvcForum.Core.Configuration;

namespace mvcForum.Web.Areas.ForumAdmin.ViewModels.Update {

	public class ForumSettingsViewModel {

		public ForumSettingsViewModel() { }
		public ForumSettingsViewModel(IConfiguration config, String themeRoot) {
			this.Editable = config.Editable;
			this.TopicsPerPage = config.TopicsPerPage;
			this.MessagesPerPage = config.MessagesPerPage;
			this.DefaultCulture = config.DefaultCulture;
			this.DefaultTimezone = config.DefaultTimezone;
			this.SiteURL = config.SiteURL;
			//this.RobotEmailAddress = config.RobotEmailAddress;
			//this.RobotName = config.RobotName;
			this.AsynchronousAntiSpam = config.AsynchronousAntiSpam;
			this.MaxAttachmentsSize = config.MaxAttachmentsSize / 1000000;
			this.MaxFileSize = config.MaxFileSize / 1000000;
			this.ShowOldPostsOnReply = config.ShowOldPostsOnReply;
			this.PostsOnReply = config.PostsOnReply;
			this.AllowUserDefinedTheme = config.AllowUserDefinedTheme;
			this.Theme = config.Theme;
			this.CheckForNews = config.CheckForNews;
			this.Editor = config.Editor;
			this.NewUserGroups = config.NewUserGroups.Select(i => i.ToString()).ToArray();
			this.AllowedExtensions = String.Join(";", config.AllowedExtensions);
			this.ShowDeletedMessages = config.ShowDeletedMessages;
			this.ShowOnlineUsers = config.ShowOnlineUsers;
			this.InformOnQuarantine = config.InformOnQuarantine;
			this.AllowQuickReply = config.AllowQuickReply;
			this.AuthorName = config.AuthorNameSetting;

			this.RedirectUrlLoggedIn = config.RedirectUrlLoggedIn;
			this.RedirectUrlLoggedOut = config.RedirectUrlLoggedOut;
			this.RedirectUrlRegistrered = config.RedirectUrlRegistrered;

			this.Themes = new String[] { };
			if (Directory.Exists(themeRoot)) {
				this.Themes = Directory.GetDirectories(themeRoot).Select(d => d.Substring(themeRoot.Length + 1)).ToArray();
			}
		}

		public Boolean Editable { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "TopicsPerPage")]
		public Int32 TopicsPerPage { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "MessagesPerPage")]
		public Int32 MessagesPerPage { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "ShowDeletedMessages")]
		public Boolean ShowDeletedMessages { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "DefaultCulture")]
		public String DefaultCulture { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "DefaultTimezone")]
		public String DefaultTimezone { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "SiteURL")]
		public String SiteURL { get; set; }
		//[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "RobotEmailAddress")]
		//public String RobotEmailAddress { get; set; }
		//public String RobotName { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "AsynchronousAntiSpam")]
		public Boolean AsynchronousAntiSpam { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "MaxFileSize")]
		public Int32 MaxFileSize { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "MaxAttachmentsSize")]
		public Int32 MaxAttachmentsSize { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "AllowedExtensions")]
		public String AllowedExtensions { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "ShowOldPostsOnReply")]
		public Boolean ShowOldPostsOnReply { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "PostsOnReply")]
		public Int32 PostsOnReply { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "AllowUserDefinedTheme")]
		public Boolean AllowUserDefinedTheme { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "Theme")]
		public String Theme { get; set; }
		public Boolean CheckForNews { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "Editor")]
		public String Editor { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "NewUserGroups")]
		public String[] NewUserGroups { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "ShowOnlineUsers")]
		public Boolean ShowOnlineUsers { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "InformOnQuarantine")]
		public Boolean InformOnQuarantine { get; set; }

		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "AllowQuickReply")]
		public Boolean AllowQuickReply { get; set; }

		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "AuthorName")]
		public AdminAuthorNameSetting AuthorName { get; set; }

		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "RedirectUrlLoggedIn")]
		public String RedirectUrlLoggedIn { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "RedirectUrlRegistrered")]
		public String RedirectUrlRegistrered { get; set; }
		[LocalizedDisplay("MVCForum.Web.ViewModels.ForumSettingsViewModel", "RedirectUrlLoggedOut")]
		public String RedirectUrlLoggedOut { get; set; }

		public String[] Themes { get; set; }
	}
}